package com.tgy.leetcode;

/**
 * @Author: tgy
 * @Date: 2/4/21 9:09 AM
 *
 * https://leetcode-cn.com/problems/maximum-average-subarray-i/
 *
 */
public class _643_子数组最大平均数_I {

    public  double findMaxAverage(int[] nums, int k) {

        int sum = 0;

        for (int i =0; i < k; ++i) {

            sum += nums[i];
        }

        int index = k;
        // 把最值赋值给初始值
        double max = sum;
        int len = nums.length;
        while (index < len) {

            sum += (nums[index] - nums[index - k]);
            max = Math.max(max,sum);
            index++;
        }

        return max * 1.0 / k;
    }

    public static void main(String[] args) {



    }
}
